package com.kkyy.findmusic.controller;

import com.kkyy.common.utils.R;
import com.kkyy.findmusic.entity.PlayListsEntity;
import com.kkyy.findmusic.service.PlayListsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigInteger;
import java.util.List;

@RestController
@RequestMapping("/findmusic")
public class PlayListsController {
    @Autowired
    private PlayListsService playListsService;

    // 查询歌单(前端)
    @RequestMapping("/playlists")
    public R getPlayLists() {
        List<PlayListsEntity> playLists = playListsService.getPlayLists2();
        return R.ok().put("data", playLists);
    }

    // 远程调用查询歌单(后台)
    @RequestMapping("/playlists2")
    public List<PlayListsEntity> getPlayLists2() {
        List<PlayListsEntity> playLists = playListsService.getPlayLists();
        return playLists;
    }

    // 远程调用删除推荐歌单
    @RequestMapping("/playlistdel")
    public void delPlayListById(@RequestParam("id") Integer id) {
        playListsService.delPlayListById(id);
    }

    // 远程调用上架推荐歌单
    @RequestMapping("/upPlaylists")
    void upPlaylistsById(@RequestParam("id") Integer id) {
        playListsService.upPlaylistsById(id);
    }

    // 远程调用下架推荐歌单
    @RequestMapping("/downPlaylists")
    void downPlaylistsById(@RequestParam("id") Integer id) {
        playListsService.downPlaylistsById(id);
    }

    @RequestMapping(value = "/addPlaylist", method = RequestMethod.GET)
    void addPlaylist(
            @RequestParam("copywriter") String copywriter,
            @RequestParam("picurl") String picurl,
            @RequestParam("playlistname") String playlistname,
            @RequestParam("location") BigInteger location) {
        playListsService.addPlaylist(copywriter, picurl, playlistname, location);
    }
}